package com.sskj.award.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.award.bean.PlatformDataBean;
import com.sskj.award.bean.SuperPlatformBean;
import com.sskj.award.ui.activity.SuperPlatformActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.lib.util.CommonUtil;

import java.util.List;

import io.reactivex.Flowable;

/**
 * @ClassName: SuperPlatformPrestener
 * @Description: 类作用描述
 * @Author: yuanlin
 * @Date: 2019/7/11 15:31
 */
public class SuperPlatformPrestener extends BasePresenter<SuperPlatformActivity> {

    public Flowable<List<SuperPlatformBean>> getData(String page, String type) {
        return httpService.getGonggaoList(page, type)
                .converter(new JsonConverter<HttpData<PageBean<SuperPlatformBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());
    }

    public void getPlatData(String page) {
        httpService.getPlatformData(page)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PlatformDataBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PlatformDataBean>> response) {
                        PlatformDataBean data = response.body().getData();
                        mView.getPlatDataSuccess(data);
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.onRefreshStop();
                    }
                });
    }

    public void upDataSuperUser(String payment_password) {
        httpService.upDataSuperUser(CommonUtil.getFiveMd5Value(payment_password))
                .tag(this)
                .execute(new JsonCallBack<HttpData<PlatformDataBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PlatformDataBean>> response) {
                        ToastUtil.showShort(response.message());
                        mView.upDataSuperUserSuccess();
                    }
                });
    }
}
